headerbar: Don't leak internal widgets
authorKalev Lember <klember@redhat.com>
Mon, 7 Dec 2015 16:21:51 +0000 (17:21 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 8 Dec 2015 03:15:25 +0000 (22:15 -0500)
Make sure to clean up internal widgets in destroy, as these aren't
cleaned up when GtkContainer walks the childrens list in
gtk_container_destroy().

This also fixes a gedit crash as reported in
https://bugzilla.redhat.com/show_bug.cgi?id=1288669

https://bugzilla.gnome.org/show_bug.cgi?id=759132

gtk/gtkheaderbar.c

index da32b350a03854c480de5e50ff30ba25cddca479..d0779bd277f8b75244b627e4ca82d98f20d85142 100644 (file)
@@ -1387,6 +1387,40 @@ gtk_header_bar_get_custom_title (GtkHeaderBar *bar)
   return priv->custom_title;
 }
 
+static void
+gtk_header_bar_destroy (GtkWidget *widget)
+{
+  GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (GTK_HEADER_BAR (widget));
+
+  if (priv->custom_title)
+    {
+      gtk_widget_unparent (priv->custom_title);
+      priv->custom_title = NULL;
+    }
+
+  if (priv->label_box)
+    {
+      gtk_widget_unparent (priv->label_box);
+      priv->label_box = NULL;
+    }
+
+  if (priv->titlebar_start_box)
+    {
+      gtk_widget_unparent (priv->titlebar_start_box);
+      priv->titlebar_start_box = NULL;
+      priv->titlebar_start_separator = NULL;
+    }
+
+  if (priv->titlebar_end_box)
+    {
+      gtk_widget_unparent (priv->titlebar_end_box);
+      priv->titlebar_end_box = NULL;
+      priv->titlebar_end_separator = NULL;
+    }
+
+  GTK_WIDGET_CLASS (gtk_header_bar_parent_class)->destroy (widget);
+}
+
 static void
 gtk_header_bar_finalize (GObject *object)
 {
@@ -1842,6 +1876,7 @@ gtk_header_bar_class_init (GtkHeaderBarClass *class)
   object_class->get_property = gtk_header_bar_get_property;
   object_class->set_property = gtk_header_bar_set_property;
 
+  widget_class->destroy = gtk_header_bar_destroy;
   widget_class->size_allocate = gtk_header_bar_size_allocate;
   widget_class->get_preferred_width = gtk_header_bar_get_preferred_width;
   widget_class->get_preferred_height = gtk_header_bar_get_preferred_height;